# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=gstreamer

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}0.10"
pkgver=0.10.36
pkgrel=1
pkgdesc="GStreamer Multimedia Framework (mingw-w64)"
arch=('any')
url="http://gstreamer.freedesktop.org/"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config" "intltool" "gtk-doc" "flex" "bison")
depends=(
    "${MINGW_PACKAGE_PREFIX}-gcc-libs"
    "${MINGW_PACKAGE_PREFIX}-libxml2"
    "${MINGW_PACKAGE_PREFIX}-glib2"
    )
options=(!libtool strip staticlibs)
source=("${url}/src/gstreamer/gstreamer-${pkgver}.tar.xz"
    tests-remove-silly-test_fail_abstract_new-check.patch
    bison3.patch
    gstreamer-0.10.36-warnings.patch)
md5sums=('15389c73e091b1dda915279c388b9cb2'
         '91a87efd72dc1c6308da7dd3357a8a1f'
         '0c402cb1f1a9629479cff6950ce97624'
         'f9511cb21cc53e15b9384174607472e3')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -Np1 -i ${srcdir}/tests-remove-silly-test_fail_abstract_new-check.patch
  patch -Np1 -i ${srcdir}/bison3.patch
  patch -Np0 -i ${srcdir}/gstreamer-0.10.36-warnings.patch
  sed -e 's/AM_CONFIG_HEADER/AC_CONFIG_HEADERS/' -i configure.ac
}

build() {
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  cp -r "${srcdir}/${_realname}-${pkgver}" "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --disable-static \
    --enable-shared \
    --enable-silent-rules \
    --disable-poisoning \
    --disable-gtk-doc \
    --enable-docbook \
    --enable-check \
    --enable-debug
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make -j1 DESTDIR="$pkgdir" install
  
  #Remove unversioned gst-* binaries to get rid of conflicts
  cd "${pkgdir}${MINGW_PREFIX}/bin"
  for bins in `ls *-0.10.exe`; do
    rm -f ${bins/-0.10.exe/}.exe
  done
  rm -f ${pkgdir}${MINGW_PREFIX}/lib/gstreamer-*/*.a
  find "${pkgdir}${MINGW_PREFIX}" -name '*.def' -o -name '*.exp' | xargs -rtl1 rm
}
